<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件委托</title>
    <style>
        ul {
            background-color: aquamarine;
            display: flex;
            margin: 0;
            padding: 0;
        }

        li {
            margin: 20px 20px;
            background-color: rgb(241, 179, 179);
            width: 300px;
            height: 100px;
            list-style: none;
            line-height: 100px;
            text-align: center;
            color: #fff;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <p>我不能被触发</p>
    </ul>

    <script>
        // 事件委托 
        const ul = document.querySelector('ul')
        ul.addEventListener('click', function (e) {
            // 指定元素
            if (e.target.tagName === 'LI') {
                // 通过夫事件对象，获取点击的子元素
                e.target.style.color = 'black'
            }

        })
    </script>
</body>

</html>